//
//  HJBaseViewController.m
//  DaiChaoApp
//
//  Created by apple on 2019/2/25.
//  Copyright © 2019年 apple. All rights reserved.
//

#import "HJBaseViewController.h"
#import "YFNavigationbar.h"


@interface HJBaseViewController ()

@end

@implementation HJBaseViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = [UIColor colorWithHex:0xf1f0f0];
    if ([self respondsToSelector:@selector(setEdgesForExtendedLayout:)]) {
        [self setEdgesForExtendedLayout:UIRectEdgeNone];
    }
    // 设置导航栏
//    [self setupNavigationBar];
    // 创建fmdb
//    [[HJFMDBDataSoure instance] configFMDB];
}
///**
// 设置导航栏
// */
//- (void)setupNavigationBar {
//    CGRect barFrame = CGRectMake(0, 0, SCREEN_WIDTH, STATUS_BAR_HEIGHT + 54);
//    YFNavigationBar *bar = [[YFNavigationBar alloc] initWithFrame:barFrame];
//    bar.backgroundImage = [UIImage imageNamed:@"navigationBar"];
//    if (self.navigationController.viewControllers.count > 1) {
//        bar.backImage = [UIImage imageNamed:@"back_left"];
//        [bar.backButton addTarget:self action:@selector(navigationBackButtonPopAction) forControlEvents:(UIControlEventTouchUpInside)];
//    }
//    [self.view addSubview:bar];
//    [self.view bringSubviewToFront:bar];
//    self.navigaitonBar = bar;
//}

#pragma mark - Setter

- (void)setNavTitle:(NSString *)navTitle {
    _navTitle = navTitle;
    self.navigationItem.title = navTitle;
}

- (void)setLeftNavTitle:(NSString *)leftNavTitle {
    _leftNavTitle = leftNavTitle;
    if (self.leftNavImageName.length) {
        [self configLeftButton];
        return;
    }
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:leftNavTitle style:UIBarButtonItemStylePlain target:self action:@selector(didClickLeftNavAction)];
}

- (void)setRightNavTitle:(NSString *)rightNavTitle {
    _rightNavTitle = rightNavTitle;
     self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:rightNavTitle style:UIBarButtonItemStylePlain target:self action:@selector(didClickRightNavAction)];
}

- (void)setRightNavImageName:(NSString *)rightNavImageName {
    _rightNavImageName = rightNavImageName;
   [self configRightButton];
}

- (void)setLeftNavImageName:(NSString *)leftNavImageName {
    _leftNavImageName = leftNavImageName;
   [self configLeftButton];
}
- (void)configLeftButton {
    UIButton *leftBtn = [self configButtonWithTitle:self.leftNavTitle image:self.leftNavImageName];
//    leftBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
//    leftBtn.titleEdgeInsets = UIEdgeInsetsMake(0, -20, 0, 0);
    leftBtn.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:leftBtn];
    [leftBtn addTarget:self action:@selector(didClickLeftNavAction) forControlEvents:UIControlEventTouchUpInside];
}
-(void)configRightButton {
    UIButton * rightBtn = [self configButtonWithTitle:self.rightNavTitle image:self.rightNavImageName];
    rightBtn.imageEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    rightBtn.titleEdgeInsets = UIEdgeInsetsMake(0, 0, 0, 0);
    rightBtn.contentHorizontalAlignment =UIControlContentHorizontalAlignmentRight;
    self.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:rightBtn];
    [rightBtn addTarget:self action:@selector(didClickRightNavAction) forControlEvents:UIControlEventTouchUpInside];
}
-(UIButton *)configButtonWithTitle:(NSString *)title image:(NSString *)image {
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    btn.frame = CGRectMake(0, 0, 60, 30);
    btn.titleLabel.font = [UIFont systemFontOFSize16];
    [btn setTitleColor:HJColorRGB(51) forState:0];
    [btn setTitle:title forState:0];
    [btn setTitle:title forState:UIControlStateHighlighted];
    [btn setImage:[UIImage imageNamed:image] forState:0];
    [btn setImage:[UIImage imageNamed:image] forState:UIControlStateHighlighted];
    return btn;
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
    [self.view endEditing:YES];
}
- (void)didClickLeftNavAction {
    
}

- (void)didClickRightNavAction {
    
}

#pragma mark - 导航栏返回按钮点击事件，子类可重写
- (void)navigationBackButtonPopAction {
    [self.navigationController popViewControllerAnimated:YES];
}

#pragma mark - Lazy Load
- (YFEmptyView *)tipEmptyView {
    if (!_tipEmptyView) {
        _tipEmptyView = [YFEmptyView view];
        _tipEmptyView.message = @"暂无数据";
    }
    return _tipEmptyView;
}

- (void)dealloc {
    [mNotificationCenter removeObserver:self];
}
-(void)ClasFrom:(NSString *)classStr {
    Class myClazz = NSClassFromString(classStr);
    if (myClazz) {
        UIViewController * myClassInit = (UIViewController *)[[myClazz alloc] init];
        [self.navigationController pushViewController:myClassInit animated:YES];
    }
}
@end
